home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / objcissu.lha / subclass-vs-protocol < prev    next >
Internet Message Format  |  1993-02-27  |  5KB

  1. Date: Fri, 26 Feb 93 14:56:31 CST
  2. From: liberte@ncsa.uiuc.edu (Daniel LaLiberte)
  3. To: gnu-objc@prep.ai.mit.edu
  4. Subject: Separating Use and Subclass interfaces
  5.  
  6. I would like to encourage the idea of separating the use and subclass
  7. interfaces, as Bill Burcham has suggested.  
  8.  
  9. Users (not subclasses) of a class need only know that it is a class and
  10. it has a set of methods associated with it, which is essentially a
  11. protocol.  These two facts need to be associated so I suggest extending
  12. the @class notation to include the protocol.  This way, two interface
  13. files could be written for each class (see example below).  We should
  14. come up with different names for them; interface and protocol mean
  15. about the same thing.  We need a different name for the file that
  16. declares the instance vars.
  17.  
  18. One extra concern is @public instance vars.  Perhaps it would be best
  19. to just require that the instance var file be imported when @public
  20. instance vars are used.
  21.  
  22. For example, here are two interface files for MyClass and another file
  23. that uses MyClass:
  24.  
  25. //===========================================
  26. // MyClassProtocol.h
  27. // Declaration of MyClassProtocol
  28. // This is for users of MyClass
  29.  
  30. // Import headers it depends on, etc
  31. ...
  32.  
  33. -thisMethod;
  34. -thatMethod;
  35.  
  36. // Declaration that MyClass is a class with MyClassProtocol
  37. @class MyClass <MyClassProtocol>     // <<<<<< new notation
  38.  
  39.  
  40. //===========================================
  41. // MyClass.h
  42. // Declaration of MyClass
  43. // This is for subclasses of MyClass.
  44.  
  45. #import "MyClassProtocol.h"
  46.  
  47. // Import protocol files for classes of statically declared instance vars.
  48. ...
  49.  
  50. @interface MyClass:Object
  51. {
  52. id thing1,thing2;
  53. ...
  54. }
  55.  
  56.  
  57. //===========================================
  58. // Foo.m
  59.  
  60. // Users of MyClass would say simply:
  61. #import "MyClassProtocol.h"
  62.  
  63. MyClass *foo;
  64.  
  65. =======================================================
  66.  
  67. Since users of a class will usually only import the protocol file,
  68. the naming convention for files should probably change so that the
  69. protocol file is the name of the class, e.g. MyClassProtocol.h should
  70. be named just MyClass.h.  Then what is the new name for "MyClass.h"?
  71.  
  72. dan
  73.  
  74. From: Steve_Naroff@NeXT.COM (Steve Naroff)
  75. Date: Sat, 27 Feb 93 08:46:49 -0800
  76. To: athan@object.com (Andrew Athan)
  77. Subject: Use/Subclass Interface distinction
  78. Cc: billb@jupiter.fnbc.com (Bill Burcham), lupson@geom.umn.edu,
  79.         gnu-objc@gnu.ai.mit.edu
  80.  
  81.  
  82. I agree with you. Requiring multiple interface files per class is a bad idea. Developers have enough of a burden managing changes between the .h and the .m, lets not *require* a third file.
  83.  
  84. Bill's goal of hiding implementation details is worthwhile, however I don't believe it should be limited to the "use" case. Encapsulation and modularity are important for both users and subclassers. Granting  subclassers special access rights is often a premature optimization that "ties the hands" of library writers.
  85.  
  86. This isn't solely a language issue, development environments must share in the "blame". For example, you could imagine a tool that provides different "views" of an interface...implementors of a kit would see one view, users of a kit would see another view. The .h files would provide the "lowest level" view for constructing other views. In the NeXT environment, we have a tool called HeaderViewer for integrating access to headers and documentation...this is where we could provide filtered views (omit ivar declarations, etc).
  87.  
  88. On the language side, protocols provide support for clearly separating interface from implementation. Andrew, could you send me any feedback you have on protocols? I am really interested in seeing this feature flushed out...
  89.  
  90. To summarize, we should resist complicating the language if the problem is a lack of support from the software development environment. Unfortunately, it is often easier the change the language (given the diversity of environments we all work with).
  91.  
  92. Oh well,
  93.  
  94. snaroff.
  95.  
  96. btw...does "don't dislike" evaluate into "like" (or something less)?
  97.  
  98. From: greg@sce.carleton.ca (Greg Franks)
  99. Date: Sat, 27 Feb 93 18:05:37 EST
  100. To: gnu-objc@gnu.ai.mit.edu
  101. In-Reply-To: Steve Naroff's message of Sat, 27 Feb 93 08:46:49 -0800 <9302271647.AA09458@oz.NeXT.COM>
  102. Subject: Use/Subclass Interface distinction
  103.  
  104. Steve_Naroff@NeXT.COM (Steve Naroff) writes:
  105.  
  106. > I agree with you. Requiring multiple interface files per class is a  
  107. > bad idea. Developers have enough of a burden managing changes between  
  108. > the .h and the .m, lets not *require* a third file. 
  109.  
  110. However, the .h file can be generated automatically from the .m file.,
  111. so an '.if' file (or whatever) can be too.
  112.  
  113. We here at Carleton already have a simple shell script to manage
  114. changes to the method names.
  115.   ..greg
  116.  
  117.